<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="ECMAScript &amp;#x662F;&amp;#x4E00;&amp;#x79CD;&amp;#x7531; Ecma &amp;#x56FD;&amp;#x9645;&amp;#x524D;&amp;#x8EAB;&amp;#x4E3A;&amp;#x6B27;&amp;#x6D32;&amp;#x8BA1;&amp;#x7B97;&amp;#x673A;&amp;#x5236;&amp;#x9020;&amp;#x5546;&amp;#x534F;&amp;#x4F1A;,&amp;#x82F1;&amp;#x6587;&amp;#x540D;&amp;#x79F">
<meta property="og:type" content="article">
<meta property="og:title" content="js 初识">
<meta property="og:url" content="https://hongqinma.github.io/2014/03/07/js-初识/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="ECMAScript &amp;#x662F;&amp;#x4E00;&amp;#x79CD;&amp;#x7531; Ecma &amp;#x56FD;&amp;#x9645;&amp;#x524D;&amp;#x8EAB;&amp;#x4E3A;&amp;#x6B27;&amp;#x6D32;&amp;#x8BA1;&amp;#x7B97;&amp;#x673A;&amp;#x5236;&amp;#x9020;&amp;#x5546;&amp;#x534F;&amp;#x4F1A;,&amp;#x82F1;&amp;#x6587;&amp;#x540D;&amp;#x79F">
<meta property="og:updated_time" content="2016-11-07T14:57:55.619Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js 初识">
<meta name="twitter:description" content="ECMAScript &amp;#x662F;&amp;#x4E00;&amp;#x79CD;&amp;#x7531; Ecma &amp;#x56FD;&amp;#x9645;&amp;#x524D;&amp;#x8EAB;&amp;#x4E3A;&amp;#x6B27;&amp;#x6D32;&amp;#x8BA1;&amp;#x7B97;&amp;#x673A;&amp;#x5236;&amp;#x9020;&amp;#x5546;&amp;#x534F;&amp;#x4F1A;,&amp;#x82F1;&amp;#x6587;&amp;#x540D;&amp;#x79F">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2014/03/07/js-初识/"/>


  <title> js 初识 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                js 初识
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2014-03-07T14:01:16+08:00" content="2014-03-07">
              2014-03-07
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2014/03/07/js-初识/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2014/03/07/js-初识/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2014/03/07/js-初识/" class="leancloud_visitors" data-flag-title="js 初识">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">visitors </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
          <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>ECMAScript &#x662F;&#x4E00;&#x79CD;&#x7531; Ecma &#x56FD;&#x9645;&#x524D;&#x8EAB;&#x4E3A;&#x6B27;&#x6D32;&#x8BA1;&#x7B97;&#x673A;&#x5236;&#x9020;&#x5546;&#x534F;&#x4F1A;,<br>&#x82F1;&#x6587;&#x540D;&#x79F0;&#x662F;European Computer Manufacturers Association&#xFF0C;&#x5236;&#x5B9A;&#x7684;&#x6807;&#x51C6;&#x3002;<br> JavaScript &#x662F;&#x7531;&#x516C;&#x53F8;&#x5F00;&#x53D1;&#x800C;&#x6210;&#x7684;&#xFF0C;&#x516C;&#x53F8;&#x5F00;&#x53D1;&#x800C;&#x6210;&#x7684;&#x4E00;&#x5B9A;&#x662F;&#x6709;&#x4E00;&#x4E9B;&#x95EE;&#x9898;&#xFF0C;<br>&#x4E0D;&#x4FBF;&#x4E8E;&#x5176;&#x4ED6;&#x7684;&#x516C;&#x53F8;&#x62D3;&#x5C55;&#x548C;&#x4F7F;&#x7528;&#x3002;&#x6240;&#x4EE5;&#x6B27;&#x6D32;&#x7684;&#x8FD9;&#x4E2A;ECMA&#x7684;&#x7EC4;&#x7EC7;&#xFF0C;<br>&#x7275;&#x5934;&#x5236;&#x5B9A; JavaScript &#x7684;&#x6807;&#x51C6;&#xFF0C;&#x53D6;&#x540D;&#x4E3A; ECMAScript&#x3002;<br><strong>&#x7B80;&#x5355;&#x6765;&#x8BF4; ECMAScript &#x4E0D;&#x662F;&#x4E00;&#x95E8;&#x8BED;&#x8A00;&#xFF0C;&#x800C;&#x662F;&#x4E00;&#x4E2A;&#x6807;&#x51C6;&#x3002;</strong><br>&#x7B26;&#x5408;&#x8FD9;&#x4E2A;&#x6807;&#x51C6;&#x7684;&#x6BD4;&#x8F83;&#x5E38;&#x89C1;&#x7684;&#x6709;&#xFF1A;JavaScript&#x3001;Action Script&#xFF08;Flash&#x4E2D;&#x7528;&#x7684;&#x8BED;&#x8A00;&#xFF09;&#x3002;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x4F60;JavaScript&#x5B66;&#x5B8C;&#x4E86;&#xFF0C;Flash&#x4E2D;&#x7684;&#x7A0B;&#x5E8F;&#x4E5F;&#x4F1A;&#x5199;&#x4E86;&#x3002;<br> ECMAScript &#x5728; 2015 &#x5E74; 6 &#x6708;&#xFF0C;&#x53D1;&#x5E03;&#x4E86; ECMAScript 6 &#x7248;&#x672C;&#xFF0C;&#x8BED;&#x8A00;&#x7684;&#x80FD;&#x529B;&#x66F4;&#x5F3A;&#x3002;</p>
<h2 id="javaScript-&#x6982;&#x5FF5;&#x3001;&#x7EC4;&#x6210;"><a href="#javaScript-&#x6982;&#x5FF5;&#x3001;&#x7EC4;&#x6210;" class="headerlink" title="javaScript &#x6982;&#x5FF5;&#x3001;&#x7EC4;&#x6210;"></a>javaScript &#x6982;&#x5FF5;&#x3001;&#x7EC4;&#x6210;</h2><p>&#x6982;&#x5FF5;&#xFF1A;js&#x662F;&#x4E00;&#x95E8;&#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x8FDB;&#x884C;&#x4EA4;&#x4E92;&#x7684;&#x7F51;&#x9875;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;</p>
<p>&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684; JavaScript&#x5B9E;&#x73B0;&#x5E94;&#x8BE5;&#x7531;&#x4E0B;&#x5217;&#x4E09;&#x4E2A;&#x90E8;&#x5206;&#x7EC4;&#x6210;&#xFF1A;</p>
<ul>
<li>&#x7EC4;&#x6210;&#xFF1A;<ul>
<li>ECMAScript js&#x6807;&#x51C6; </li>
<li>dom &#x53EF;&#x4EE5;&#x5229;&#x7528;JS&#x64CD;&#x4F5C;&#x7F51;&#x9875;&#x5143;&#x7D20;</li>
<li>Bom &#x901A;&#x8FC7;api&#x6765;&#x64CD;&#x4F5C;&#x6D4F;&#x89C8;&#x5668; </li>
</ul>
</li>
</ul>
<h3 id="ECMAScript"><a href="#ECMAScript" class="headerlink" title="ECMAScript"></a>ECMAScript</h3><p>web &#x6D4F;&#x89C8;&#x5668;&#x662F; ECMAScript &#x5B9E;&#x73B0;&#x53EF;&#x80FD;&#x7684;&#x5BBF;&#x4E3B;&#x73AF;&#x5883;&#x4E4B;&#x4E00;&#xFF0C;ECMAScript &#x89C4;&#x5B9A;&#x4E86;&#x8BED;&#x8A00;&#x7684;&#x7684;&#x4E0B;&#x5217;&#x7EC4;&#x6210;&#x90E8;&#x5206;&#xFF1A;</p>
<ul>
<li>&#x8BED;&#x6CD5;</li>
<li>&#x7C7B;&#x578B;</li>
<li>&#x8BED;&#x53E5;</li>
<li>&#x5173;&#x952E;&#x5B57;</li>
<li>&#x4FDD;&#x7559;&#x5B57;</li>
<li>&#x64CD;&#x4F5C;&#x7B26;</li>
<li>&#x5BF9;&#x8C61;</li>
</ul>
<p>ECMAScript &#x5C31;&#x662F;&#x5BF9;&#x5B9E;&#x73B0;&#x8FD9;&#x4E2A;&#x6807;&#x51C6;&#x89C4;&#x5B9A;&#x7684;&#x5404;&#x65B9;&#x9762;&#x5185;&#x5BB9;&#x7684;&#x8BED;&#x8A00;&#x63CF;&#x8FF0;&#x3002;</p>
<h3 id="DOM-&#x6587;&#x6863;&#x5BF9;&#x8C61;&#x6A21;&#x578B;-&#x7B80;&#x4ECB;"><a href="#DOM-&#x6587;&#x6863;&#x5BF9;&#x8C61;&#x6A21;&#x578B;-&#x7B80;&#x4ECB;" class="headerlink" title="DOM &#x6587;&#x6863;&#x5BF9;&#x8C61;&#x6A21;&#x578B; &#x7B80;&#x4ECB;"></a>DOM &#x6587;&#x6863;&#x5BF9;&#x8C61;&#x6A21;&#x578B; &#x7B80;&#x4ECB;</h3><p>&#x6587;&#x6863;&#x5BF9;&#x8C61;&#x6A21;&#x578B;&#x662F;&#x9488;&#x5BF9; XML &#x4F46;&#x7ECF;&#x8FC7;&#x6269;&#x5C55;&#x7528;&#x4E8E; HTML &#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7F16;&#x7A0B;&#x63A5;&#x53E3;&#x3002;<br>DOM &#x628A;&#x6574;&#x4E2A;&#x9875;&#x9762;&#x6620;&#x5C04;&#x4E3A;&#x4E00;&#x4E2A;&#x591A;&#x5C42;&#x8282;&#x70B9;&#x7ED3;&#x6784;&#x3002;HTML &#x6216; XML &#x9875;&#x9762;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x7EC4;&#x6210;&#x90E8;&#x5206;&#x90FD;&#x662F;&#x67D0;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x8282;&#x70B9;&#xFF0C;<br>&#x8FD9;&#x4E9B;&#x8282;&#x70B9;&#x53C8;&#x5305;&#x542B;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<h3 id="BOM-&#x6D4F;&#x89C8;&#x5668;&#x5BF9;&#x8C61;&#x6A21;&#x578B;-&#x7B80;&#x4ECB;"><a href="#BOM-&#x6D4F;&#x89C8;&#x5668;&#x5BF9;&#x8C61;&#x6A21;&#x578B;-&#x7B80;&#x4ECB;" class="headerlink" title="BOM &#x6D4F;&#x89C8;&#x5668;&#x5BF9;&#x8C61;&#x6A21;&#x578B; &#x7B80;&#x4ECB;"></a>BOM &#x6D4F;&#x89C8;&#x5668;&#x5BF9;&#x8C61;&#x6A21;&#x578B; &#x7B80;&#x4ECB;</h3><p>BOM &#x53EA;&#x5904;&#x7406;&#x6D4F;&#x89C8;&#x5668;&#x7A97;&#x53E3;&#x548C;&#x6846;&#x67B6;&#xFF0C;&#x4E60;&#x60EF;&#x4E0A;&#x628A;&#x6240;&#x6709;&#x9488;&#x5BF9;&#x6D4F;&#x89C8;&#x5668;&#x7684; JavaScrip &#x6269;&#x5C55;&#x7B97;&#x4F5C; BOM &#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;&#x5982;&#xFF1A;</p>
<ul>
<li>&#x5F39;&#x51FA;&#x65B0;&#x6D4F;&#x89C8;&#x5668;&#x7A97;&#x53E3;</li>
<li>&#x79FB;&#x52A8;&#x3001;&#x7F29;&#x653E;&#x548C;&#x5173;&#x95ED;&#x6D4F;&#x89C8;&#x5668;&#x7A97;&#x53E3;&#x7684;&#x529F;&#x80FD;</li>
<li>&#x63D0;&#x4F9B;&#x6D4F;&#x89C8;&#x5668;&#x4FE1;&#x606F;&#x4FE1;&#x606F;&#x7684; navigator &#x5BF9;&#x8C61;</li>
<li>&#x63D0;&#x4F9B;&#x6D4F;&#x89C8;&#x5668;&#x6240;&#x52A0;&#x8F7D;&#x9875;&#x9762;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#x7684; location &#x5BF9;&#x8C61;</li>
<li>&#x63D0;&#x4F9B;&#x7528;&#x6237;&#x663E;&#x793A;&#x5668;&#x5206;&#x8FA8;&#x7387;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#x7684; screen &#x5BF9;&#x8C61;</li>
<li>&#x5BF9; cookie &#x7684;&#x652F;&#x6301;</li>
<li>&#x50CF; XMLHttpRequest &#x548C; IE &#x7684; ActiveXObject &#x8FD9;&#x6837;&#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;</li>
</ul>
<p>&#x7531;&#x4E8E;&#x6CA1; BOM &#x7EDF;&#x4E00;&#x6807;&#x51C6;&#xFF0C;&#x6240;&#x4EE5;&#x5404;&#x4E2A;&#x6D4F;&#x89C8;&#x5668;&#x90FD;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x5B9E;&#x73B0;&#x529F;&#x80FD;&#xFF0C;<br>&#x5C3D;&#x7BA1;&#x5404;&#x89C4;&#x5B9A;&#x6D4F;&#x89C8;&#x5668;&#x90FD;&#x5B9E;&#x73B0; <code>window</code> &#x5BF9;&#x8C61;&#x548C; <code>navigator</code>  &#x5BF9;&#x8C61;&#xFF1B;</p>
<ul>
<li>JavaScript &#x7684;&#x7279;&#x70B9;<ul>
<li>&#x7B80;&#x5355;&#x6613;&#x7528; </li>
<li>&#x57FA;&#x4E8E;&#x5BF9;&#x8C61;</li>
<li>&#x57FA;&#x4E8E;&#x8FC7;&#x7A0B;</li>
<li>&#x89E3;&#x91CA;&#x6267;&#x884C;&#xFF1A;js&#x5F15;&#x64CE;&#x6765;&#x6267;&#x884C;&#x6E90;&#x4EE3;&#x7801; &#xFF0C; node &#x5E73;&#x53F0;</li>
</ul>
</li>
<li>&#x7F16;&#x8BD1;&#x6267;&#x884C;&#x7C7B;&#x8BED;&#x8A00;&#x6709;&#xFF1A;Java c# &#x6E90;&#x4EE3;&#x7801; ==&gt; &#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;.dll ==&gt; &#x7535;&#x8111;&#x6267;&#x884C;.dll&#x8BFE;&#x6267;&#x884C;&#x6587;&#x4EF6;</li>
<li>&#x4F7F;&#x7528;&#x8303;&#x56F4;&#xFF1A;<ul>
<li>&#x8868;&#x5355;&#x9A8C;&#x8BC1;</li>
<li>&#x8F6E;&#x64AD;&#x56FE;&#x7279;&#x6548;</li>
<li>&#x6E38;&#x620F;&#x5F00;&#x53D1;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="lt-script-gt-lt-script-gt-&#x5143;&#x7D20;"><a href="#lt-script-gt-lt-script-gt-&#x5143;&#x7D20;" class="headerlink" title="&lt;script&gt;&lt;/script&gt; &#x5143;&#x7D20;"></a><code>&lt;script&gt;&lt;/script&gt;</code> &#x5143;&#x7D20;</h2><p><code>&lt;script&gt;&lt;/script&gt;</code> &#x5B9A;&#x4E49;&#x4E86;6&#x4E2A;&#x5C5E;&#x6027;</p>
<ul>
<li>async: &#x53EF;&#x9009;&#x3002;&#x7ACB;&#x5373;&#x4E0B;&#x8F7D;&#x811A;&#x6807;&#xFF0C;&#x5BF9;&#x9875;&#x9762;&#x4E2D;&#x5176;&#x4ED6;&#x5143;&#x7D20;&#x6CA1;&#x6709;&#x5F71;&#x54CD;&#x3002;&#x53EA;&#x5BF9;&#x5916;&#x90E8;&#x811A;&#x6807;&#x6587;&#x4EF6;&#x6709;&#x6548;</li>
<li>charset: &#x53EF;&#x9009;&#x3002; &#x8868;&#x793A;&#x901A;&#x8FC7; src &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x5B57;&#x7B26;&#x96C6;&#x3002;&#x5927;&#x591A;&#x6570;&#x6D4F;&#x89C8;&#x5668;&#x4F1A;&#x5FFD;&#x7565;&#x5176;&#x503C;&#xFF0C;&#x5F88;&#x5C11;&#x7528;</li>
<li>defer&#xFF1A;&#x53EF;&#x9009;&#x3002; &#x8868;&#x793A;&#x811A;&#x672C;&#x53EF;&#x4EE5;&#x5EF6;&#x8FDF;&#x5230;&#x6587;&#x6863;&#x5B8C;&#x5168;&#x88AB;&#x89E3;&#x6790;&#x548C;&#x663E;&#x793A;&#x4E4B;&#x540E;&#x518D;&#x6267;&#x884C;&#x3002;&#x53EA;&#x5BF9;&#x5916;&#x90E8;&#x811A;&#x672C;&#x6709;&#x6548;</li>
<li>language: &#x5DF2;&#x5E9F;&#x5F03;&#x3002;</li>
<li>src&#xFF1A;&#x53EF;&#x9009;&#x3002;&#x8981;&#x6267;&#x884C;&#x7684;&#x5916;&#x90E8;&#x6587;&#x4EF6;</li>
<li>type&#xFF1A;&#x53EF;&#x9009;&#x3002;&#x8003;&#x8651;&#x5230;&#x6700;&#x5927;&#x7A0B;&#x5EA6;&#x7684;&#x517C;&#x5BB9;&#xFF0C;&#x4F7F;&#x7528; <code>&quot;text/javascript&quot;</code></li>
</ul>
<h3 id="js-&#x4E66;&#x5199;&#x4F4D;&#x7F6E;"><a href="#js-&#x4E66;&#x5199;&#x4F4D;&#x7F6E;" class="headerlink" title="js &#x4E66;&#x5199;&#x4F4D;&#x7F6E;"></a>js &#x4E66;&#x5199;&#x4F4D;&#x7F6E;</h3><ul>
<li>&#x5185;&#x5D4C;&#x5F0F;</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">&lt;head&gt;</div><div class="line">&lt;meta charset=&quot;utf-8&quot;&gt;</div><div class="line">&lt;title&gt;js &#x4E66;&#x5199;&#x4F4D;&#x7F6E;&lt;/title&gt;</div><div class="line">&lt;script&gt;</div><div class="line">  // js &#x4EE3;&#x7801;&#x6BB5;</div><div class="line">&lt;/script&gt;</div><div class="line">&lt;/head&gt;</div></pre></td></tr></table></figure>
<ul>
<li>&#x5916;&#x94FE;&#x5F0F;&#x5199;&#x6CD5;<ul>
<li>&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;js&#x6587;&#x4EF6;</li>
<li>&#x901A;&#x8FC7;script&#x6807;&#x7B7E;&#x91CC;&#x7684;src=&#x201D;1.js&#x201D;&#x5C5E;&#x6027;&#x5C06;JS&#x6587;&#x4EF6;&#x8C03;&#x5165;&#x5230;&#x5F53;&#x524D;&#x9875;&#x9762;&#x3002;</li>
</ul>
</li>
</ul>
<p>&#x8865;&#x5145;&#x5185;&#x5D4C;&#x5F0F;&#x5199;&#x6CD5;&#xFF1A;&#x63A8;&#x8350;Js&#x4EE3;&#x7801;&#x6700;&#x597D;&#x653E;&#x5728;body&#x7ED3;&#x675F;&#x6807;&#x7B7E;&#x7684;&#x540E;&#x8FB9;&#x3002;</p>
<h3 id="&#x5728;-XHTML-&#x4E2D;&#x7684;&#x7528;&#x6CD5;"><a href="#&#x5728;-XHTML-&#x4E2D;&#x7684;&#x7528;&#x6CD5;" class="headerlink" title="&#x5728; XHTML &#x4E2D;&#x7684;&#x7528;&#x6CD5;"></a>&#x5728; XHTML &#x4E2D;&#x7684;&#x7528;&#x6CD5;</h3><p>XHTML &#x5373;&#x53EF;&#x6269;&#x5C55;&#x7684;&#x8D85;&#x6587;&#x672C;&#x6807;&#x8BB0;&#x8BED;&#x8A00;&#xFF0C;&#x662F;&#x5C06; HTML &#x4F5C;&#x4E3A; XML &#x7684;&#x5E94;&#x7528;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x7684;&#x4E00;&#x4E2A;&#x6807;&#x51C6;&#x3002;</p>
<figure class="highlight xhtml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="xml"></span></div><div class="line">// &lt;![CDATA[</div><div class="line">  funciton foo(){</div><div class="line">    // &#x4EE3;&#x7801;&#x6BB5;</div><div class="line">  }</div><div class="line">//]]&gt;</div><div class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div></pre></td></tr></table></figure>
<hr>
<h2 id="&#x6587;&#x6863;&#x6A21;&#x5F0F;"><a href="#&#x6587;&#x6863;&#x6A21;&#x5F0F;" class="headerlink" title="&#x6587;&#x6863;&#x6A21;&#x5F0F;"></a>&#x6587;&#x6863;&#x6A21;&#x5F0F;</h2><p>doctype: &#x6807;&#x51C6;&#x6A21;&#x5F0F;&#x3001;&#x6DF7;&#x6742;&#x6A21;&#x5F0F;</p>
<p>&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x5F00;&#x542F;&#xFF1A; <code>use strict;</code></p>
<hr>
<h2 id="&#x9875;&#x9762;&#x4E2D;&#x8F93;&#x51FA;&#x6D88;&#x606F;&#x7684;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;"><a href="#&#x9875;&#x9762;&#x4E2D;&#x8F93;&#x51FA;&#x6D88;&#x606F;&#x7684;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;" class="headerlink" title="&#x9875;&#x9762;&#x4E2D;&#x8F93;&#x51FA;&#x6D88;&#x606F;&#x7684;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;"></a>&#x9875;&#x9762;&#x4E2D;&#x8F93;&#x51FA;&#x6D88;&#x606F;&#x7684;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">alert(&quot;&#x4FE1;&#x606F;&quot;)   &#x5728;&#x9875;&#x9762;&#x51FA;&#x73B0;&#x4E00;&#x4E2A;&#x5F39;&#x51FA;&#x6846;&#xFF0C;&#x5C06;&#x4FE1;&#x606F;&#x5F39;&#x51FA;&#x3002;</div><div class="line">confirm(&quot;&#x4FE1;&#x606F;&quot;) &#x5728;&#x9875;&#x9762;&#x51FA;&#x73B0;&#x4E00;&#x4E2A;&#x5F39;&#x51FA;&#x6846;&#xFF0C;&#x5C06;&#x4FE1;&#x606F;&#x663E;&#x793A;&#xFF0C;&#x5E38;&#x4E0E;if&#x5224;&#x65AD;&#x8BED;&#x53E5;&#x7ED3;&#x5408;&#x4F7F;&#x7528;&#x3002;</div><div class="line">prompt(&quot;&#x4FE1;&#x606F;&quot;)  &#x5F39;&#x51FA;&#x4E00;&#x4E2A;&#x6587;&#x672C;&#x6846;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x6587;&#x672C;&#x6846;&#x63A5;&#x6536;&#x5185;&#x5BB9;&#x3002;&#x5E38;&#x7528;&#x4E8E;&#x63A5;&#x6536;&#x4FE1;&#x606F;&#x3002;</div><div class="line">console.log(&quot;&#x4FE1;&#x606F;&quot;)&#x5C06;&#x4FE1;&#x606F;&#x8F93;&#x51FA;&#x5230;&#x63A7;&#x5236;&#x53F0;&#xFF0C;&#x5E38;&#x7528;&#x4E8E;&#x4EE3;&#x7801;&#x8C03;&#x8BD5;&#x3002;</div><div class="line">document.write(&quot;&#x4FE1;&#x606F;&quot;) &#x76F4;&#x63A5;&#x5728;&#x9875;&#x9762;&#x8F93;&#x51FA;&#x6D88;&#x606F;&#x3002;</div></pre></td></tr></table></figure>
<p>&#x6CE8;&#xFF1A;document.write(&#x201C;&#x4FE1;&#x606F;&#x201D;)&#xFF0C;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x8F93;&#x51FA;&#x5185;&#x5BB9;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x8F93;&#x51FA;html&#x6807;&#x7B7E;&#x3002;</p>
<hr>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将是我最大的鼓励！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/js/" rel="tag">#js</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2013/09/17/HTML元素分类、伪类、背景图片/" rel="next" title="HTML元素分类、伪类、背景图片">
                <i class="fa fa-chevron-left"></i> HTML元素分类、伪类、背景图片
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2014/03/12/js-词法结构/" rel="prev" title="js 词法结构">
                js 词法结构 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2014/03/07/js-初识/"
     data-title="js 初识"
     data-content=""
     data-url="https://hongqinma.github.io/2014/03/07/js-初识/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2014/03/07/js-初识/"
           data-title="js 初识" data-url="https://hongqinma.github.io/2014/03/07/js-初识/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">20</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#javaScript-概念、组成"><span class="nav-number">1.</span> <span class="nav-text">javaScript 概念、组成</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#ECMAScript"><span class="nav-number">1.1.</span> <span class="nav-text">ECMAScript</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DOM-文档对象模型-简介"><span class="nav-number">1.2.</span> <span class="nav-text">DOM 文档对象模型 简介</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#BOM-浏览器对象模型-简介"><span class="nav-number">1.3.</span> <span class="nav-text">BOM 浏览器对象模型 简介</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#lt-script-gt-lt-script-gt-元素"><span class="nav-number">2.</span> <span class="nav-text"><script></script> 元素</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#js-书写位置"><span class="nav-number">2.1.</span> <span class="nav-text">js 书写位置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在-XHTML-中的用法"><span class="nav-number">2.2.</span> <span class="nav-text">在 XHTML 中的用法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文档模式"><span class="nav-number">3.</span> <span class="nav-text">文档模式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#页面中输出消息的几种方式"><span class="nav-number">4.</span> <span class="nav-text">页面中输出消息的几种方式</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
